// components/receive/examineApprove/examineApprove.js
import api from '../../../utils/api';
Component({
  /**
   * 组件的属性列表
   */
  properties: {
    claimId:'', // 认领ID
    flowId:'',  // 流程ID
    abolishId:'',//作废ID
  },

  /**
   * 组件的初始数据
   */
  data: {
    fixed: true,
    message: '',
    show: false
  },

  /**
   * 组件的方法列表
   */
  methods: {
    // 输入审批意见
    onInput() {
      this.setData({
        show: true
      })
    },
    //  关闭弹窗
    onClose() {
      this.setData({
        show: false
      })
    },
    onChange(e){
      console.log(e)
      this.setData({
        message:e.detail
      })
    },
    // 拒绝
    onDecline() {
      let that = this;
      if(that.data.abolishId){
        api.rejectClaimAbolish({
          data:{
            abolishId:that.data.abolishId,
            flowNote:that.data.message
          },
          success:function(res){
            if(res.data.code==200){
              wx.showToast({
                title: '审批成功',
              })
              setTimeout(() => {
                wx.navigateBack({
                  delta: 1,
                })
              }, 100);
            }else{
              wx.showModal({
                content:res.data.message,
                showCancel:false,
                confirmColor:'#0041C4'
              })
            }
          }
        })
      }else{
        api.rejectClaim({
          data: {
            claimId:that.data.claimId,
            flowId:that.data.flowId,
            flowNotes:that.data.message
          },
          success: function (res) {
            console.log(res)
            if(res.data.code==200){
              wx.showToast({
                title: '审批成功',
              })
              setTimeout(() => {
                wx.navigateBack({
                  delta: 1,
                })
              }, 100);
            }else{
              wx.showModal({
                content:res.data.message,
                showCancel:false,
                confirmColor:'#0041C4'
              })
            }
          }
        })
      }
      
    },
    // 同意
    onAgree() {
      let that = this;
      if(that.data.abolishId){
        api.approveClaimAbolish({
          data:{
            abolishId:that.data.abolishId,
            flowNote:that.data.message
          },
          success:function(res){
            if(res.data.code==200){
              wx.showToast({
                title: '审批成功',
              })
              setTimeout(() => {
                wx.navigateBack({
                  delta: 1,
                })
              }, 100);
            }else{
              wx.showModal({
                content:res.data.message,
                showCancel:false,
                confirmColor:'#0041C4'
              })
            }
          }
        })
      }else{
        api.approveClaim({
          data: {
            claimId:that.data.claimId,
            flowId:that.data.flowId,
            flowNotes:that.data.message
          },
          success: function (res) {
            console.log(res)
            if(res.data.code==200){
              wx.showToast({
                title: '审批成功',
              })
              setTimeout(() => {
                wx.navigateBack({
                  delta: 1,
                })
              }, 100);
            }else{
              wx.showModal({
                content:res.data.message,
                showCancel:false,
                confirmColor:'#0041C4'
              })
            }
          }
        })
      }
    }
  }
})